package logic

import (
	"context"
	"good_srv/model/mysql"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *good.OrderListRequest) (*good.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var order []mysql.Order
	mysql.DB.Find(&order)
	var allorder []*good.OrderList
	for _, m := range order {
		lists := good.OrderList{
			UserId:    m.UserId,
			Numbering: m.Numbering,
			Title:     m.Title,
			Times:     m.Times,
			Status:    m.Status,
			Total:     float32(m.Total),
		}
		allorder = append(allorder, &lists)
	}
	return &good.OrderListResponse{
		List: allorder,
	}, nil
}
